package com.ponhu.ea2.service.facade;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ponhu.ea2.common.basic.model.PagedResult;
import com.ponhu.ea2.query.PickInventoryQuery;
import com.ponhu.ea2.vo.PickExportVo;
import com.ponhu.ea2.vo.PickInventoryDetailVo;
import com.ponhu.ea2.vo.PickInventoryStatisticsVo;
import com.ponhu.ea2.vo.PickInventoryVo;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Wang
 * @date 2021/12/10 5:47 下午
 */
public interface PickInventoryManageService {

    default void trimAndConvertHandler(PickInventoryQuery query) {
        if (StringUtils.isNotEmpty(query.getInventoryCode())){
            query.setInventoryCode(query.getInventoryCode().trim());
        }
        if (CollectionUtils.isNotEmpty(query.getInventoryCodeList())){
            query.setInventoryCodeList(query.getInventoryCodeList().stream().map(String::trim).collect(Collectors.toList()));
        }
        if (StringUtils.isNotEmpty(query.getInventoryName())){
            query.setInventoryName(query.getInventoryName().trim());
        }
        if (StringUtils.isNotEmpty(query.getMaterialCode())){
            query.setMaterialCode(query.getMaterialCode().trim());
        }
        if (StringUtils.isNotEmpty(query.getModelName())){
            query.setModelName(query.getModelName().trim());
        }
        if (StringUtils.isNotEmpty(query.getSeriesName())){
            query.setSeriesName(query.getSeriesName().trim());
        }
        if (StringUtils.isNotEmpty(query.getPropertyBagNo())){
            query.setPropertyBagNo(query.getPropertyBagNo().trim());
        }
        if (StringUtils.isNotEmpty(query.getPropertyWatchNo())){
            query.setPropertyWatchNo(query.getPropertyWatchNo().trim());
        }
        if (StringUtils.isNotEmpty(query.getVendorName())){
            query.setVendorName(query.getVendorName().trim());
        }
        if (StringUtils.isNotEmpty(query.getRemarks())){
            query.setRemarks(query.getRemarks().trim());
        }
        if (StringUtils.isNotEmpty(query.getMaintainResult())){
            query.setMaintainResult(query.getMaintainResult().trim());
        }
        if (StringUtils.isNotEmpty(query.getCreateTimeStart())) {
            query.setCreateTimeStart(query.getCreateTimeStart() + " 00:00:00");
        }
        if (StringUtils.isNotEmpty(query.getCreateTimeEnd())) {
            query.setCreateTimeEnd(query.getCreateTimeEnd() + " 23:59:59");
        }
        //如果最小实物库存为0，最大实物库存为空，那么意味着查询所有
        if(query.getRealStockNumMin() != null && query.getRealStockNumMin() == 0 && query.getRealStockNumMax() == null){
            query.setRealStockNumMin(null);
        }
        //如果最小实物库存为空，最大实物库存为0，那么意味着查询为0的实物库存
        if(query.getRealStockNumMin() == null && query.getRealStockNumMax() != null  && query.getRealStockNumMax() == 0 ){
            query.setRealStockNumMin(0);
        }
    }
    /**
     * 根据条件分页查询选品列表数据
     * @param pickInventoryQuery
     * @return
     */
    PagedResult<PickInventoryVo> getPickInventoryListByCondition(PickInventoryQuery pickInventoryQuery);


    /**
     * 根据条件查询导出的选品详细数据（限制3000条）
     * @param pickInventoryQuery
     * @return
     */
    List<PickInventoryDetailVo> exportPickInventoryDataList(PickInventoryQuery pickInventoryQuery);

    /**
     * 根据货品ID查询选品
     * @param inventoryId
     * @return
     */
    PickInventoryDetailVo getPickInventoryByInventoryId(Long inventoryId);

    /**
     * 根据ID获取选品详情数据(ES)
     * @param inventoryId
     * @param pickInventoryRule 是否拥有KPI货品权限（yes: 有， no:无）
     * @return
     */
    PickInventoryDetailVo getPickInventoryByInventoryId(Long inventoryId, String pickInventoryRule);

    <T extends PickExportVo> List<PickExportVo> getPickExportVoList(PickInventoryQuery query, Class<T> tClass);

    /**
     * 选品列表汇总结果查询
     * @param query
     * @return
     */
    PickInventoryStatisticsVo getPickInventoryStatisticsInfo(PickInventoryQuery query);

    /**
     * 选品列表结果查询(ES)
     * @param query
     * @return
     */
    PagedResult<PickInventoryVo> getPickInventoryListFromES(PickInventoryQuery query) throws IOException;

    /**
     * 选品列表汇总结果查询(ES)
     * @param query
     * @return
     */
    PickInventoryStatisticsVo getPickInventoryStatisticsInfoFromES(PickInventoryQuery query);

    /**
     * 根据ID获取选品详情数据(ES)
     * @param inventoryId
     * @param result
     * @return
     */
    PickInventoryDetailVo getPickInventoryByInventoryIdFromES(Long inventoryId, String result);

    List<PickInventoryDetailVo> exportPickInventoryDataListFromEs(PickInventoryQuery query);
}
